import {
    printObject,
    browser
} from './API/index'
import {
    loadbaseApi
} from './API/api'
import {
    cjcAuth
} from './API/privateAPI'
import {
    loadPageApi
} from './API/PageApi'
import {
    loadUserApi
} from './API/user'

export default class ITfer {
    constructor() {
        this.browser = browser
        loadPageApi(this)
        loadbaseApi(this)
        loadUserApi(this) // 加载用户相关api
        this.printObject = printObject
    }
    viewInit() {
        if (this.browser.versions.ios || this.browser.versions.android) {
            this.setupWebViewJavascriptBridge(function(bridge) {})
        }
    }
    cjcAuth(auth) {
        return cjcAuth(auth, this)
    }
    setupWebViewJavascriptBridge(callback) {
        if (window.WebViewJavascriptBridge) {
            return callback(window.WebViewJavascriptBridge)
        }
        if (window.WVJBCallbacks) {
            return window.WVJBCallbacks.push(callback)
        }
        window.WVJBCallbacks = [callback]
        let WVJBIframe = document.createElement('iframe')
        WVJBIframe.style.display = 'none'
        WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__'
        document.documentElement.appendChild(WVJBIframe)
        setTimeout(function() {
            document.documentElement.removeChild(WVJBIframe)
        }, 0)
    }
    cjcLog(str) {
        // document.getElementById('logArea').innerHTML += '\n' + str
        console.log(str)
    }
    cjcAnalys(str) {
        this.cjcLog('cjcAnalys 检测到一次请求' + str)
    }
}
if (window.iTfer) {
    window.iTfer = new ITfer()
}
